import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service - 消息管理/发送配置
 * @date: 2018-8-21
 * @version: 1.0.0


 */
import request from 'utils/request';
import { CPAAS_MSG } from 'utils/config';
import { parseParameters, getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();
/**
 * 查询模板服务映射列表数据
 * @async
 * @function querySMSList
 * @param {object} params - 查询条件
 * @param {!number} [params.page = 0] - 数据页码
 * @param {!number} [params.size = 10] - 分页大小
 * @returns {object} fetch Promise
 */

export function querySMSList(_x) {
  return _querySMSList.apply(this, arguments);
}
/**
 * 删除模板服务
 * @async
 * @function deleteHeader
 * @param {object} params - 请求参数
 * @param {!object} params.tempServerId - 消息模板ID
 */

function _querySMSList() {
  _querySMSList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-servers") : "".concat(CPAAS_MSG, "/v1/template-servers"), {
              method: 'GET',
              query: _objectSpread({}, param)
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _querySMSList.apply(this, arguments);
}

export function deleteHeader(_x2) {
  return _deleteHeader.apply(this, arguments);
}
/**
 * 编辑条件头查询
 * @async
 * @function searchApproveHeader
 * @param {object} params - 查询条件
 * @param {?string} params.tempServerId - 消息模板ID
 * @returns {object} fetch Promise
 */

function _deleteHeader() {
  _deleteHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-servers/").concat(params.tempServerId) : "".concat(CPAAS_MSG, "/v1/template-servers/").concat(params.tempServerId), {
              method: 'DELETE',
              body: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _deleteHeader.apply(this, arguments);
}

export function searchHeader(_x3) {
  return _searchHeader.apply(this, arguments);
}
/**
 * 复制
 * @param {*} params
 */

function _searchHeader() {
  _searchHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-servers/line/").concat(params.tempServerId) : "".concat(CPAAS_MSG, "/v1/template-servers/line/").concat(params.tempServerId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _searchHeader.apply(this, arguments);
}

export function searchCopyHeader(_x4) {
  return _searchCopyHeader.apply(this, arguments);
}
/**
 * 新增
 * @async
 * @function saveHeader
 * @param {object} params - 请求参数
 * @param {!object} params.dto - 待保存对象
 */

function _searchCopyHeader() {
  _searchCopyHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-servers/").concat(params.tempServerId, "/copy") : "".concat(CPAAS_MSG, "/v1/template-servers/").concat(params.tempServerId, "/copy"), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _searchCopyHeader.apply(this, arguments);
}

export function saveHeader(_x5) {
  return _saveHeader.apply(this, arguments);
}
/**
 * 更新
 * @async
 * @function updateHeader
 * @param {object} params - 请求参数
 * @param {!string} params.tempServerId - 消息模板ID
 * @param {!object} params.dto - 待保存对象
 */

function _saveHeader() {
  _saveHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-servers") : "".concat(CPAAS_MSG, "/v1/template-servers"), {
              method: 'POST',
              body: _objectSpread({}, params.dto)
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _saveHeader.apply(this, arguments);
}

export function updateHeader(_x6) {
  return _updateHeader.apply(this, arguments);
}
/**
 * 删除行服务
 * @async
 * @function deleteHeader
 * @param {object} params - 请求参数
 * @param {!object} params.recordTempServerLineId - 参数ID
 */

function _updateHeader() {
  _updateHeader = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-servers/").concat(params.tempServerId) : "".concat(CPAAS_MSG, "/v1/template-servers/").concat(params.tempServerId), {
              method: 'PUT',
              body: _objectSpread({}, params.dto)
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _updateHeader.apply(this, arguments);
}

export function deleteLine(_x7) {
  return _deleteLine.apply(this, arguments);
}
/**
 * 获取语言类型
 * @async
 * @function fetchLangType
 * @param {object} params - 请求参数
 */

function _deleteLine() {
  _deleteLine = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-servers/line/").concat(params.tempServerLineId) : "".concat(CPAAS_MSG, "/v1/template-servers/line/").concat(params.tempServerLineId), {
              method: 'DELETE',
              body: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _deleteLine.apply(this, arguments);
}

export function fetchLangType(_x8) {
  return _fetchLangType.apply(this, arguments);
}
/**
 * 改变语言，获取参数名称
 * @async
 * @function getParams
 * @param {object} params - 请求参数
 */

function _fetchLangType() {
  _fetchLangType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/message/templates/template-lang") : "".concat(CPAAS_MSG, "/v1/message/templates/template-lang"), {
              method: 'GET',
              query: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _fetchLangType.apply(this, arguments);
}

export function getParams(_x9) {
  return _getParams.apply(this, arguments);
}
/**
 * 发送消息
 * @async
 * @function sendMessage
 * @param {object} params - 请求参数
 */

function _getParams() {
  _getParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/message/templates/template-args") : "".concat(CPAAS_MSG, "/v1/message/templates/template-args"), {
              method: 'GET',
              query: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _getParams.apply(this, arguments);
}

export function sendMessage(_x10) {
  return _sendMessage.apply(this, arguments);
}
/**
 * 获取模板数据
 * @param {object} params
 */

function _sendMessage() {
  _sendMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            return _context10.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/message/relevance/all") : "".concat(CPAAS_MSG, "/v1/message/relevance/all"), {
              method: 'POST',
              body: _objectSpread({}, params)
            }));

          case 1:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _sendMessage.apply(this, arguments);
}

export function fetchTemplateData(_x11) {
  return _fetchTemplateData.apply(this, arguments);
}
/**
 * 获取模板数据
 * @param {object} params
 */

function _fetchTemplateData() {
  _fetchTemplateData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(params) {
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            return _context11.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/message/templates/template-code") : "".concat(CPAAS_MSG, "/v1/message/templates/template-code"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _fetchTemplateData.apply(this, arguments);
}

export function GetWebhook(_x12) {
  return _GetWebhook.apply(this, arguments);
}
/**
 * 获取模板数据
 * @param {object} params
 */

function _GetWebhook() {
  _GetWebhook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(params) {
    var tempServerLineId;
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            tempServerLineId = params.tempServerLineId;
            return _context12.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-server-whs/").concat(tempServerLineId) : "".concat(CPAAS_MSG, "/v1/template-server-whs/").concat(tempServerLineId), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _GetWebhook.apply(this, arguments);
}

export function deleteWebhook(_x13) {
  return _deleteWebhook.apply(this, arguments);
}
/**
 * 获取模板数据
 * @param {object} params
 */

function _deleteWebhook() {
  _deleteWebhook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(params) {
    var tempServerLineId, payload;
    return _regeneratorRuntime.wrap(function _callee13$(_context13) {
      while (1) {
        switch (_context13.prev = _context13.next) {
          case 0:
            tempServerLineId = params.tempServerLineId, payload = params.payload;
            return _context13.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-server-whs/").concat(tempServerLineId) : "".concat(CPAAS_MSG, "/v1/template-server-whs/").concat(tempServerLineId), {
              method: 'DELETE',
              body: payload
            }));

          case 2:
          case "end":
            return _context13.stop();
        }
      }
    }, _callee13);
  }));
  return _deleteWebhook.apply(this, arguments);
}

export function createWebhook(_x14) {
  return _createWebhook.apply(this, arguments);
}

function _createWebhook() {
  _createWebhook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(params) {
    var tempServerLineId, payload;
    return _regeneratorRuntime.wrap(function _callee14$(_context14) {
      while (1) {
        switch (_context14.prev = _context14.next) {
          case 0:
            tempServerLineId = params.tempServerLineId, payload = params.payload;
            return _context14.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/template-server-whs/").concat(tempServerLineId) : "".concat(CPAAS_MSG, "/v1/template-server-whs/").concat(tempServerLineId), {
              method: 'POST',
              body: payload
            }));

          case 2:
          case "end":
            return _context14.stop();
        }
      }
    }, _callee14);
  }));
  return _createWebhook.apply(this, arguments);
}